using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using MemberMgr.Data.ManagerObjects;
using MemberMgr.Data.BusinessObjects;
using MemberMgr.Data.Base;

namespace MemberMgr.Data.UnitTests
{
	[TestFixture]
    public partial class tConsumptionDetailTests : UNuitTestBase
    {
        protected ItConsumptionDetailManager manager;
		
		public tConsumptionDetailTests()
        {
            manager = managerFactory.GettConsumptionDetailManager();
        }
		
		protected tConsumptionDetail CreateNewtConsumptionDetail()
		{
			tConsumptionDetail entity = new tConsumptionDetail();
			
			
			entity.Price = 14;
			entity.Count = 28;
			entity.Productcut = "Test Test ";
			
			ItConsumptionMasterManager tConsumptionMasterManager = managerFactory.GettConsumptionMasterManager();
			entity.TConsumptionMaster = tConsumptionMasterManager.GetAll(1)[0];
			
			ItProductManager tProductManager = managerFactory.GettProductManager();
			entity.TProduct = tProductManager.GetAll(1)[0];
			
			return entity;
		}
		protected tConsumptionDetail GetFirsttConsumptionDetail()
        {
            IList<tConsumptionDetail> entityList = manager.GetAll(1);
            if (entityList.Count == 0)
                Assert.Fail("All tables must have at least one row for unit tests to succeed.");
            return entityList[0];
        }
		
		[Test]
        public void Create()
        {
            try
            {
				tConsumptionDetail entity = CreateNewtConsumptionDetail();
				
                object result = manager.Save(entity);

                Assert.IsNotNull(result);
            }
            catch(Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
        [Test]
        public void Read()
        {
            try
            {
                tConsumptionDetail entityA = CreateNewtConsumptionDetail();
				manager.Save(entityA);

                tConsumptionDetail entityB = manager.GetById(entityA.Id);

                Assert.AreEqual(entityA, entityB);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
		[Test]
		public void Update()
        {
            try
            {
                tConsumptionDetail entityA = GetFirsttConsumptionDetail();
				
				entityA.Price = 32;
				
				manager.Update(entityA);

                tConsumptionDetail entityB = manager.GetById(entityA.Id);

                Assert.AreEqual(entityA.Price, entityB.Price);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
        [Test]
        public void Delete()
        {
            try
            {
                tConsumptionDetail entity = GetFirsttConsumptionDetail();
				
                manager.Delete(entity);

                entity = manager.GetById(entity.Id);
                Assert.IsNull(entity);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
	}
}

